/**
 * Created by Administrator on 2017/5/10 0010.
 */
define(["jquery", "template", "scprit/department/view/template/monitorList-temTpl.js"], function ($, template, tpl) {
    var question = {};
    var inTable = function (data) {
        return template("temList", data);
    }
    question.listInit = function (options) {
        $("body").append(tpl.init());
        var html = inTable(options);
        $(options.id).html(html);
    }
    question.nameDeal=function (name){
        var username;
        var len=name.length;
        if(len>3){
            username=name.substring(0,3);
        }else{
            username=name
        }
        return username;
    }
    question.timeLong=  function(obj,attr,userName){
        for(var i=0;i<obj.length;i++){
            var duration;
            var username=obj[i][userName];
            var timeLong=obj[i][attr];//获得秒数；
            var d=parseInt(timeLong/(24*3600));
            var h=parseInt(timeLong/3600);
            var m=parseInt((timeLong%3600)/60);
            var s=parseInt((timeLong%3600)%60);
            if(d>=1){
                if(h>=1){
                    if(m>=1){
                        if(s>=1){
                            duration=d+"天"+h+"小时"+m+"分"+s+"秒";
                        }else{
                            duration=d+"天"+h+"小时"+m+"分";
                        }
                    }else{
                        if(s>=1){
                            duration=d+"天"+h+"小时"+s+"秒";
                        }else{
                            duration=d+"天"+h+"小时";
                        }
                    }
                }else{
                    if(m>=1){
                        if(s>=1){
                            duration=d+"天"+m+"分"+s+"秒";
                        }else{
                            duration=d+"天"+m+"分";
                        }
                    }else{
                        if(s>=1){
                            duration=d+"天"+s+"秒";
                        }else{
                            duration=d+"天";
                        }
                    }
                }
            }else{
                if(h>=1){
                    if(m>=1){
                        if(s>=1){
                            duration=h+"小时"+m+"分"+s+"秒";
                        }else{
                            duration=h+"小时"+m+"分";
                        }
                    }else{
                        if(s>=1){
                            duration=h+"小时"+s+"秒";
                        }else{
                            duration=h+"小时";
                        }
                    }
                }else{
                    if(m>=1){
                        if(s>=1){
                            duration=m+"分"+s+"秒";
                        }else{
                            duration=m+"分";
                        }
                    }else{
                        if(s>=1){
                            duration=s+"秒";
                        }else{
                            duration="暂无数据";
                        }
                    }
                }
            }
            obj[i][attr]=duration;
            obj[i][userName]=this.nameDeal(username);
        }
        return obj;
    };
    return question;
});
